package com.dq.service.Impl;

import com.dq.mapper.AdminMapper;
import com.dq.pojo.Admin;
import com.dq.utils.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class AdminServiceImpl {

    @Autowired
    private AdminMapper adminMapper;

    public Admin login(Admin admin) {

        admin = adminMapper.selectAdmin(admin);

        return admin;
    }

    public Map<String, Object> updateAvatar(String avatarName) {

        Long userId = BaseContext.getCurrentId();

        adminMapper.updateAvatar(avatarName, userId);

        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("data", "");
        map.put("msg", "更新头像成功");
        return map;
    }

    public Map<String, Object> selectById() {
        Long id = BaseContext.getCurrentId();

        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("data", adminMapper.selectById(id));
        map.put("msg", "查询用户信息成功");
        return map;

    }
}
